package io.e2x.testground.fruitstore.common;

import io.e2x.testground.fruitstore.data.Coupon;

import java.math.BigDecimal;

public class CouponUtils {

    public static BigDecimal withCoupon(Coupon coupon, BigDecimal price) {
        switch (coupon.getType()){
            case REDUCTION:
            {
                if(price.compareTo(coupon.getLimit()) > 0) {
                    return price.subtract(coupon.getValue());
                }
            }
            default:
                return price;
        }
    }
    public static String getCouponName(Coupon coupon) {
        return switch (coupon.getType()){
            case REDUCTION -> "满减券";
            case DISCOUNT -> "折扣券";
            default -> "无";
        };
    }
    public static Integer getCouponType(Coupon coupon) {
        return switch (coupon.getType()){
            case REDUCTION -> 2;
            case DISCOUNT -> 1;
            default -> 0;
        };
    }
}
